{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "min_dis=10\n",
    "max_dis=150\n",
    "count=20\n",
    "\n",
    "dis=np.random.randint(10,150,20)\n",
    "pos=np.zeros(dis.shape)\n",
    "pos[0]=dis[0]\n",
    "for i  in range(dis.shape[0]-1):\n",
    "    pos[i+1]=dis[i+1]+pos[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def CalcPostAddr(H:list)->list:\n",
    "    \"\"\"\n",
    "    使用贪心算法计算邮局位置\n",
    "    参数:\n",
    "    H: 房子位置列表，已经排好序\n",
    "    返回值:\n",
    "    P: 邮局位置列表\n",
    "    \"\"\"\n",
    "    \n",
    "    P=[]\n",
    "    P.append(H[0]+100)\n",
    "    for h in H:\n",
    "        if abs(P[-1]-h)>100:\n",
    "            P.append(h+100)\n",
    "    return P\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "房子位置： [ 139.  191.  213.  271.  351.  409.  533.  667.  797.  810.  917.  994.\n",
      " 1075. 1201. 1327. 1436. 1517. 1666. 1708. 1730.]\n",
      "邮局位置: [239.0, 451.0, 767.0, 1017.0, 1301.0, 1536.0, 1766.0]\n"
     ]
    }
   ],
   "source": [
    "H=pos\n",
    "print(\"房子位置：\" ,H)\n",
    "print(\"邮局位置:\",CalcPostAddr(pos))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:math]",
   "language": "python",
   "name": "conda-env-math-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
